<?php
/*
Example usage :

Connect :
$db->connect($db_host, $db_user, $db_pass, $db_name);

Query :
$query = $db->query("");

Return one row :
$query = $db->query("");
$r = $db->fetch_array($query);
$var = $r[column];

Return more than one row :
$query = $db->query("");
while($r = $db->fetch_row($query)) {
$stuff = $r[0];
}

Close connection :
$db->close();
*/
class db {

    function connect($db_host, $db_user, $db_pass, $db_name) {
      mysql_connect($db_host, $db_user, $db_pass);
      mysql_select_db("$db_name") or die(mysql_error());
    }

    function query($query) {
      $query = mysql_query($query) or die(mysql_error());
      return $query;
    }

    function fetch_array($query) {
      $query = mysql_fetch_array($query);
      return $query;
    }

    function fetch_row($query) {
      $query = mysql_fetch_row($query);
      return $query;
    }

    function num_results($query) {
      $query = mysql_num_rows($query);
      return $query;
    }

    function last_inserted() {
      $last_id = mysql_insert_id();
      return $last_id;
    }

    function close() {
      mysql_close();
    }

    function reset($query) {
      mysql_data_seek($query,0);
    }
}
?>
